//
//  SMPopupButton.swift
//  SomePasti
//
//  Created by 李永彬 on 2025/10/9.
//

import SwiftUI

// 弹窗类型枚举
enum SMPopupStyle {
    case alert          // 从中间弹出
    case actionSheet    // 从底部弹出
}

// 弹窗配置
struct SMPopupConfig {
    var style: SMPopupStyle = .alert
    var backgroundColor: Color = .clear
    var backgroundImage: String?
    var cornerRadius: CGFloat = 14
    var overlayColor: Color = .black.opacity(0.4)
    var animation: Animation = .spring(response: 0.3, dampingFraction: 0.8)
    var dismissOnTapOutside: Bool = true
    
    // Alert 样式特定配置
    var alertWidth: CGFloat = 270
    
    // ActionSheet 样式特定配置
    var actionSheetMaxHeight: CGFloat = 400
    var showDragIndicator: Bool = true
    
    // 背景图片配置
    var backgroundImageContentMode: ContentMode = .fit
    var backgroundImageOpacity: Double = 1.0
    
    // 阴影配置
    var shadowColor: Color = .black.opacity(0.2)
    var shadowRadius: CGFloat = 10
    var padding: CGFloat = 16
}

enum SMPopupButtonStyle {
    case `default`
    case destructive
    case cancel
    
    var textColor: Color {
        return Color.white
    }
    
    var backgroundColor: Color {
        switch self {
        case .cancel: return Color.red
        default: return Color.blue
        }
    }
    
    var buttonHeight: CGFloat {
        switch self {
        case .cancel: return 44
        default: return 44
        }
    }
    
    var cornerRadius: CGFloat {
        return 8
    }
}

// 弹窗按钮
struct SMPopupButton: View {
    let title: String
    let style: SMPopupButtonStyle
    let action: () -> Void
    
    init(_ title: String, style: SMPopupButtonStyle = .default, action: @escaping () -> Void) {
        self.title = title
        self.style = style
        self.action = action
    }
    
    var body: some View {
        Button(action: action) {
            Text(title)
                .font(.body)
                .fontWeight(style == .cancel ? .semibold : .regular)
                .foregroundColor(style.textColor)
                .frame(maxWidth: .infinity)
                .frame(height: style.buttonHeight)
                .contentShape(Rectangle())
        }
        .buttonStyle(PlainButtonStyle())
        .background(style.backgroundColor)
        .cornerRadius(style.cornerRadius)
    }
}

